/* Original Author:  Dominick O'Dierno
 * Date: 2007   odiernod@gmail.com     --Originally intended for use with DOMercury:  http://www.odierno.com/domercury
 * Description: Manages any reads or writes to the registry. So far used only to generate parameters for the OpenWith action
 * 
 * --CHANGELOG--
 * 
 * */
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using DOMercury.Interfaces;
using DOMercury.Items;

namespace DOMercury.Managers
{
    public static class RegistryManager
    {
        public static List<IItem> GetOpenWithExes(string ItemType)
        {
            List<IItem> progs = new List<IItem>();
            string type = ItemType;
            try
            {
                string skey = "Software\\Classes\\*\\OpenWithList";
                RegistryKey key = Registry.LocalMachine.OpenSubKey(skey);
                foreach (string k in key.GetSubKeyNames())
                {
                    progs.Add(new TextItem(k));
                }
            }
            catch
            {
                
            } 
            if (type != ".*")
            {
               try
                {
                    string skey = "Software\\Classes\\" + type + "\\OpenWithList";
                    RegistryKey key = Registry.LocalMachine.OpenSubKey(skey);
                    string[] temp = key.GetSubKeyNames();
                    foreach (string s in temp)
                    {
                        if ((progs.Find(delegate (IItem m){return m.DisplayName == s;}) == null))
                        {
                            progs.Add(new TextItem(s));
                        }
                    }
                }
                catch
                {

                } 
            }
            progs.Sort();
            return progs;
        }
           
    }
}
